<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>结构型设计模式详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .pattern-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.18);
        }
        
        .pattern-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            overflow: hidden;
            position: relative;
        }
        
        .code-header {
            background: #2d2d2d;
            padding: 8px 16px;
            font-size: 12px;
            color: #888;
            border-bottom: 1px solid #3e3e3e;
        }
        
        pre {
            margin: 0;
            padding: 16px;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        
        .pattern-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 16px;
            font-size: 24px;
            color: white;
            margin-bottom: 20px;
        }
        
        .decorator-icon { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); }
        .adapter-icon { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); }
        .proxy-icon { background: linear-gradient(135deg, #fa709a 0%, #fee140 100%); }
        .bridge-icon { background: linear-gradient(135deg, #30cfd0 0%, #330867 100%); }
        
        .section-title {
            position: relative;
            display: inline-block;
            margin-bottom: 2rem;
        }
        
        .section-title::after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 0;
            width: 60px;
            height: 4px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .mermaid {
            background: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        }
        
        .highlight-text {
            background: linear-gradient(120deg, #f093fb 0%, #f5576c 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            font-weight: 600;
        }
        
        .floating-shape {
            position: absolute;
            border-radius: 50%;
            opacity: 0.1;
            animation: float 20s infinite ease-in-out;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0) rotate(0deg); }
            50% { transform: translateY(-20px) rotate(180deg); }
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white relative overflow-hidden">
        <div class="floating-shape w-64 h-64 bg-white top-10 right-10"></div>
        <div class="floating-shape w-32 h-32 bg-white bottom-10 left-20" style="animation-delay: 5s;"></div>
        
        <div class="container mx-auto px-6 py-20 relative z-10">
            <div class="max-w-4xl">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                    结构型设计模式
                    <span class="block text-3xl md:text-4xl mt-4 font-light opacity-90">构建灵活可扩展的软件架构</span>
                </h1>
                <p class="text-xl md:text-2xl font-light leading-relaxed opacity-90">
                    深入探索装饰器、适配器、代理和桥接模式，掌握如何优雅地组织代码结构，提升系统的灵活性与可维护性。
                </p>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-16">
        <!-- Introduction -->
        <div class="max-w-4xl mx-auto mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
                <p class="text-lg leading-relaxed text-gray-700 indent-8">
                    装饰器模式、适配器模式、代理模式和桥接模式都是结构型设计模式，它们各自解决不同的设计问题。这些模式在设计中各有其独特的用途和适用场景，有助于提高代码的灵活性、可维护性和可扩展性。
                </p>
            </div>
        </div>

        <!-- Pattern Relationship Diagram -->
        <div class="max-w-6xl mx-auto mb-16">
            <h2 class="section-title text-3xl font-bold text-gray-800 mb-8">
                <i class="fas fa-project-diagram mr-3 text-purple-600"></i>模式关系图谱
            </h2>
            <div class="mermaid">
                graph TB
                    A[结构型设计模式] --> B[装饰器模式]
                    A --> C[适配器模式]
                    A --> D[代理模式]
                    A --> E[桥接模式]
                    
                    B --> B1[动态添加功能]
                    B --> B2[保持接口一致]
                    
                    C --> C1[接口转换]
                    C --> C2[兼容性处理]
                    
                    D --> D1[访问控制]
                    D --> D2[延迟加载]
                    
                    E --> E1[抽象与实现分离]
                    E --> E2[独立扩展]
                    
                    style A fill:#667eea,stroke:#764ba2,stroke-width:3px,color:#fff
                    style B fill:#f093fb,stroke:#f5576c,stroke-width:2px,color:#fff
                    style C fill:#4facfe,stroke:#00f2fe,stroke-width:2px,color:#fff
                    style D fill:#fa709a,stroke:#fee140,stroke-width:2px,color:#fff
                    style E fill:#30cfd0,stroke:#330867,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Pattern Cards -->
        <div class="grid grid-cols-1 lg:grid-cols-2 gap-8 max-w-6xl mx-auto">
            <!-- Decorator Pattern -->
            <div class="pattern-card rounded-2xl p-8">
                <div class="pattern-icon decorator-icon">
                    <i class="fas fa-layer-group"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4 text-gray-800">装饰器模式</h3>
                <p class="text-gray-600 mb-6">
                    <strong class="text-gray-800">目的：</strong>动态地给对象添加额外的功能，而不影响到其他对象。
                </p>
                <p class="text-gray-600 mb-6">
                    <strong class="text-gray-800">实现方式：</strong>通过创建一个装饰器类，这个类与被装饰的对象实现相同的接口，并且持有对被装饰对象的引用。装饰器类可以在调用原始对象的方法之前或之后添加额外的行为。
                </p>
                <p class="text-gray-600 mb-6">
                    <strong class="text-gray-800">应用场景：</strong>当你需要在不修改现有代码的情况下，动态地为对象添加新功能时。
                </p>
                
                <div class="code-block">
                    <div class="code-header">
                        <i class="fab fa-java mr-2"></i>Java 示例代码
                    </div>
                    <pre><code>// 组件接口
public interface Coffee {
    String getDescription();
    double cost();
}

// 具体组件
public class SimpleCoffee implements Coffee {
    public String getDescription() {
        return "Simple Coffee";
    }
    public double cost() {
        return 5.0;
    }
}

// 装饰器
public abstract class CoffeeDecorator implements Coffee {
    protected Coffee decoratedCoffee;
    public CoffeeDecorator(Coffee coffee) {
        this.decoratedCoffee = coffee;
    }
    public String getDescription() {
        return decoratedCoffee.getDescription();
    }
    public double cost() {
        return decoratedCoffee.cost();
    }
}

// 具体装饰器
public class MilkDecorator extends CoffeeDecorator {
    public MilkDecorator(Coffee coffee) {
        super(coffee);
    }
    public String getDescription() {
        return super.getDescription() + ", Milk";
    }
    public double cost() {
        return super.cost() + 1.0;
    }
}</code></pre>
                </div>
            </div>

            <!-- Adapter Pattern -->
            <div class="pattern-card rounded-2xl p-8">
                <div class="pattern-icon adapter-icon">
                    <i class="fas fa-plug"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4 text-gray-800">适配器模式</h3>
                <p class="text-gray-600 mb-6">
                    <strong class="text-gray-800">目的：</strong>将一个类的接口转换成客户端所期望的另一个接口，使得原本因接口不兼容而不能一起工作的类可以一起工作。
                </p>
                <p class="text-gray-600 mb-6">
                    <strong class="text-gray-800">实现方式：</strong>通过创建一个适配器类，这个类实现了客户端期望的接口，并且持有被适配对象的引用。适配器类在实现接口方法时，调用被适配对象的方法来完成实际的操作。
                </p>
                <p class="text-gray-600 mb-6">
                    <strong class="text-gray-800">应用场景：</strong>当你需要将一个已有的类的接口转换为另一个客户端期望的接口时。
                </p>
                
                <div class="code-block">
                    <div class="code-header">
                        <i class="fab fa-java mr-2"></i>Java 示例代码
                    </div>
                    <pre><code>// 目标接口
public interface Target {
    void request();
}

// 被适配的类
public class Adaptee {
    public void specificRequest() {
        System.out.println("Specific request");
    }
}

// 适配器类
public class Adapter implements Target {
    private Adaptee adaptee;
    public Adapter(Adaptee adaptee) {
        this.adaptee = adaptee;
    }
    public void request() {
        adaptee.specificRequest();
    }
}</code></pre>
                </div>
            </div>

            <!-- Proxy Pattern -->
            <div class="pattern-card rounded-2xl p-8">
                <div class="pattern-icon proxy-icon">
                    <i class="fas fa-shield-alt"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4 text-gray-800">代理模式</h3>
                <p class="text-gray-600 mb-6">
                    <strong class="text-gray-800">目的：</strong>为一个对象提供一个代理对象，以控制对该对象的访问。代理对象可以在访问真实对象前后添加额外的处理。
                </p>
                <p class="text-gray-600 mb-6">
                    <strong class="text-gray-800">实现方式：</strong>创建一个代理类，代理类与被代理对象实现相同的接口，并持有被代理对象的引用。代理类可以在调用被代理对象的方法之前或之后执行其他操作，如日志记录、权限检查等。
                </p>
                <p class="text-gray-600 mb-6">
                    <strong class="text-gray-800">应用场景：</strong>当你需要控制对某个对象的访问，或在访问对象时执行额外操作时。
                </p>
                
                <div class="code-block">
                    <div class="code-header">
                        <i class="fab fa-java mr-2"></i>Java 示例代码
                    </div>
                    <pre><code>// 真实对象接口
public interface RealSubject {
    void request();
}

// 真实对象实现
public class Real